package model;

import java.util.Scanner;

/*
 * 绯荤粺绫�
 */
public class Sys {
	private Scanner scan = new Scanner(System.in);
	private User[] users = new User[2];
	private Menu[] menus = new Menu[5];
	private Order[] orders = new Order[4];
	public Sys(){
		
		//鍒濆鍖栫敤鎴�
		//1銆佸垱寤烘櫘閫氱敤鎴凤紱
		User binbin = new User("binbin","123",2);
		//2銆佸垱寤哄晢瀹剁敤鎴凤紱
		User root = new User("root","123",1);
		//瀛樻斁鍦ㄧ敤鎴锋暟缁勯噷锛�
		users[0] = binbin;
		users[1] = root;
		
		//鍒濆鍖栬彍鍗曪紱
		Menu menu1 = new Menu("閰歌彍楸�",38,0);
		Menu menu2 = new Menu("榫欒櫨",128,0);
		Menu menu3 = new Menu("鍟ら厭楦�",58,0);
		menus[0] = menu1;
		menus[1] = menu2;
		menus[2] = menu3;
	}
	
	//鏄剧ず鐧诲綍鑿滃崟锛�
	public boolean showLoginMenu(){
		System.out.println("***娆㈣繋浣跨敤楗夸簡涔堣椁愮郴缁�***");
		System.out.println("璇烽�夋嫨鐧诲綍瑙掕壊锛� 1銆佸晢瀹�    2銆佸鎴�");
		User user = new User();
		int role = user.inputRole();
		System.out.println("璇风敤鎴疯緭鍏ヨ处鍙峰拰瀵嗙爜锛�");
		User iuser = user.inputUser(role);//杩斿洖鐢ㄦ埛杈撳叆鐨勮处鍙峰拰瀵嗙爜锛坲ser瀵硅薄锛�
		return checkUser(iuser);
	
	}
	//鏄剧ず涓昏彍鍗�
	public int shoMenu(){
		System.out.println("1銆佽椁�");
		System.out.println("2銆佹煡璇㈣鍗�");
		System.out.println("3銆佺鏀惰鍗�");
		System.out.println("4銆佸垹闄よ鍗�");
		System.out.println("5銆佺偣璧�");
		System.out.println("6銆侀��鍑�");
		User user = new User();
		return user.inputService();
	}
	
	//楠岃瘉璐︽埛鏄惁瀛樺湪锛�
	public boolean checkUser(User user){
		for (int i = 0; i < users.length; i++) {
			if (user.getUsernamwe().equals(users[i].getUsernamwe())&&user.getPass().equals(users[i].getPass())&&user.getRole() == users[i].getRole()) {
				System.out.println("楠岃瘉閫氳繃锛�");
				return true;
			}
		}
		System.out.println("璐﹀彿鎴栬�呭瘑鐮侀敊璇紒");
		return false;
	}
	
	//鏀瑰彉璁㈠崟鐘舵��  锛堢鏀惰鍗曪級
		//鐢ㄦ埛閫夋嫨璁㈠崟
	public void changeOrder(){
		System.out.println("璇疯緭鍏ヨ绛炬敹鐨� 璁㈠崟搴忓彿锛�");
		User user  = new User();
		int num =user.inputMenu();
		orders[num-1].setStates(1);
		for (int i = 0; i < orders.length; i++) {
			if (orders[i] != null) {
				System.out.println((i+1)+"\t"+orders[i].getFoodName()+"\t"+orders[i].getFoodNum()+"\t"+orders[i].getMoney()+"\t"+orders[i].getUname()+"\t"+orders[i].getOdate()+"\t"+orders[i].getAddress()+"\t"+orders[i].getStates());
			}
		}
		System.out.println("绛炬敹瀹屾垚");
	}
	//鍒犻櫎璁㈠崟
	public void deleteOrder(){
		System.out.println("璇疯緭鍏ヨ绛炬敹鐨� 璁㈠崟搴忓彿锛�");
		User user  = new User();
	
		int num = user.inputMenu();
		orders[num-1]= null;
		for (int i = 0; i < orders.length; i++) {
			if (orders[i] != null) {
				System.out.println((i+1)+"\t"+orders[i].getFoodName()+"\t"+orders[i].getFoodNum()+"\t"+orders[i].getMoney()+"\t"+orders[i].getUname()+"\t"+orders[i].getOdate()+"\t"+orders[i].getAddress()+"\t"+orders[i].getStates());
			}
		}
		System.out.println("鍒犻櫎瀹屾垚");
	
	}
	//鐢ㄦ埛閫夋嫨瑕佺偣璧炵殑鑿滃搧搴忓彿骞惰繘琛岀偣璧烇紱
	public void giveOrder(){
		System.out.println("璇疯緭鍏ヨ鐐硅禐鐨� 鑿滃搧搴忓彿锛�");
		User user  = new User();
		int num = user.inputMenu();
	
		//for (int i = 0; i < menus.length; i++) {
			int give = menus[num-1].getGive();
			menus[num-1].setGive(++give);
			System.out.println("鐐硅禐瀹屾垚");
		//	break;
		//}
		
	
	}
	
	
	
	public Scanner getScan() {
		return scan;
	}
	public void setScan(Scanner scan) {
		this.scan = scan;
	}
	public User[] getUsers() {
		return users;
	}
	public void setUsers(User[] users) {
		this.users = users;
	}
	public Menu[] getMenus() {
		return menus;
	}
	public void setMenus(Menu[] menus) {
		this.menus = menus;
	}
	public Order[] getOrders() {
		return orders;
	}
	public void setOrders(Order[] orders) {
		this.orders = orders;
	} 

}
